using System;
using UnityEngine.UI;

namespace FutureCorePlugin
{
    public class PreSystemAffirmUI : BasePreUI<PreSystemAffirmUI>
    {
        public class ViewInfo
        {
            public string contentInfo;
            public string affirmBtnInfo;
            public string cancelBtnInfo;
            public Action affirmFunc;
            public Action cancelFunc;
        }

        private ViewInfo viewInfo;
        private Text infoTxt;
        private Text affirmTxt;
        private Text cancelTxt;
        private Button affirmBtn;
        private Button cancelBtn;

        protected override void OnInit()
        {
            resPath = "Preset/PreUI/SystemAffirmUI/SystemAffirmUI";
            uiLayer = PreUIHandler.UILayer.System;
        }

        protected override void OnBind()
        {
            infoTxt = uiTF.Find("Panel/InfoTxt").GetComponent<Text>();
            affirmTxt = uiTF.Find("Panel/AffirmBtn/AffirmTxt").GetComponent<Text>();
            cancelTxt = uiTF.Find("Panel/CancelBtn/CancelTxt").GetComponent<Text>();
            affirmBtn = uiTF.Find("Panel/AffirmBtn").GetComponent<Button>();
            cancelBtn = uiTF.Find("Panel/CancelBtn").GetComponent<Button>();
        }

        protected override void OnOpen(object param)
        {
            InitView(param);
        }

        private void InitView(object param)
        {
            viewInfo = param as ViewInfo;
            infoTxt.text = viewInfo.contentInfo;
            affirmTxt.text = viewInfo.affirmBtnInfo;
            cancelTxt.text = viewInfo.cancelBtnInfo;
            affirmBtn.onClick.AddListener(() =>
            {
                Close();
                if (viewInfo.affirmFunc != null)
                {
                    viewInfo.affirmFunc();
                }
            });
            cancelBtn.onClick.AddListener(() =>
            {
                Close();
                if (viewInfo.cancelFunc != null)
                {
                    viewInfo.cancelFunc();
                }
            });
        }
    }
}